package com.example.administrator.spritelgs.view;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.administrator.spritelgs.R;
import com.example.administrator.spritelgs.adapter.ChongZhiAdapter;
import com.example.administrator.spritelgs.bean.ChongZhiInfo;
import com.example.administrator.spritelgs.util.AnimUtil;

import java.util.ArrayList;
import java.util.List;

;

/**
 * Created by Administrator on 2017/7/1.
 */

public class ChongZhiView extends BaseView {
    private Dialog dialog;
    private ImageView iv_close;
    private FrameLayout fl_cz;
    private FrameLayout fl_dh;
    private ListView lv_cz;


    public  ChongZhiView(Context context)
    {
        super(context);
        setContentView(R.layout.view_chongzhi);

        initUI();
        initLvCzAdapter();
    }
    @Override
    protected void initUI() {
        iv_close = (ImageView)findViewById(R.id.iv_close);
        AnimUtil.addOnTouchListener(iv_close, 0.5f, 0.5f, new AnimUtil.AnimListener() {
            @Override
            public void down(View v) {

            }

            @Override
            public void move(View v) {

            }

            @Override
            public void up(View v) {
                dialog.dismiss();
            }
        });
        fl_cz = (FrameLayout)findViewById(R.id.fl_cz);
        AnimUtil.addOnTouchListener(fl_cz,0.5f,0.5f,null);
        fl_dh= (FrameLayout)findViewById(R.id.fl_dh);
        AnimUtil.addOnTouchListener(fl_dh,0.5f,0.5f,null);

        lv_cz = (ListView)findViewById(R.id.lv_cz);
    }

    private void initLvCzAdapter(){
        List<ChongZhiInfo> data = new ArrayList<ChongZhiInfo>();
        data.add(new ChongZhiInfo("优惠80%", 0.8f, "月卡大礼包", R.mipmap.item1, "包含一张月卡，3颗钻石", 68.0, "$68"));
        data.add(new ChongZhiInfo("优惠80%", 0.8f, "月卡大礼包", R.mipmap.item2, "包含一张月卡，4颗钻石", 68.0, "$78"));
        data.add(new ChongZhiInfo("优惠80%", 0.8f, "月卡大礼包", R.mipmap.item3, "包含一张月卡，5颗钻石", 68.0, "$88"));
        ChongZhiAdapter adapter = new ChongZhiAdapter(context,data);
        lv_cz.setAdapter(adapter);
    }

    public  void show(){
        if(dialog == null) {
            dialog = new Dialog(context, R.style.MyDialog);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
            dialog.setContentView(view, params);
        }
        dialog.show();
    }
}
